package com.jin.utils;

import com.jacob.activeX.ActiveXComponent;
import com.jacob.com.ComThread;
import com.jacob.com.Dispatch;
import com.jacob.com.Variant;

public class WorldUtils {
    public static void genPdf(String word,String pdf){
        // 启动WPS进程
        ActiveXComponent wps = new ActiveXComponent("KWPS.Application");

        // 可以设置WPS的可见性
        wps.setProperty("Visible", new Variant(false));

        // 打开文档
        Dispatch documents = wps.getProperty("Documents").toDispatch();
        Dispatch document = Dispatch.call(documents, "Open", word).toDispatch();


        // 转换为PDF
        Dispatch.call(document, "ExportAsFixedFormat", pdf,17);

        // 关闭文档和WPS
        Dispatch.call(document, "Close", new Variant(false));
        wps.invoke("Quit", new Variant[0]);

        // 释放资源
        document.safeRelease();
        documents.safeRelease();
        wps.safeRelease();

        ComThread.Release();


    }


}
